package com.sphd.beautysalon.model;


import com.android.volley.VolleyError;
import com.sphd.beautysalon.info.DuihuanInfo;
import com.sphd.beautysalon.presenter.IntegralRecordPresenterImpl;
import com.sphd.beautysalon.interfaces.VolleyJsonObjectCallBack;
import com.wzh.frame.utils.JsonUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by Hu on 2016/11/14
 */

public class IntegralRecordModelImpl implements IntegralRecordModel, VolleyJsonObjectCallBack {
    IntegralRecordPresenterImpl integralRecordPresenter;

    @Override
    public void sendUrl(String url, IntegralRecordPresenterImpl integralRecordPresenter) {
        this.integralRecordPresenter = integralRecordPresenter;
        volleyUtil.setJsonObjectRequest(url, this);
    }

    @Override
    public void onResponse(JSONObject response) {
        try {
            List<DuihuanInfo> duihuanInfos = JsonUtil.getListFromString(response.getString("list"), DuihuanInfo.class);
            int integral =response.getInt("integral");
            integralRecordPresenter.sendRes(duihuanInfos,integral);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onErrorResponse(VolleyError error) {

    }
}